package com.demo;

import lombok.extern.slf4j.Slf4j;

import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;


public class TestA {
    public static void main(String[] args) {
        try {
            RandomAccessFile file = new RandomAccessFile("D:\\intelij project\\learn-parent\\learn-netty\\nio-demo1\\src\\main\\resources\\helloworld\\data.txt", "rw");
            FileChannel channel = file.getChannel();
            ByteBuffer buffer = ByteBuffer.allocate(10);
            while(true){
                int len = channel.read(buffer);
                System.out.println("读到的字节数："+ len);
                if(len == -1){
                    break;
                }
                buffer.flip();// 切换到读模式
                while(buffer.hasRemaining()){
                    System.out.println("::::"+(char)buffer.get());
                }
                buffer.clear();//写模式
            }
        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
